var o = require("../../requests/request.js"), t = require("../../utils/util.js");

Page({
    data: {
        videoid: 0,
        commentcount: 0,
        author: "易车视频",
        publishTime: "",
        totalVisit: 0,
        categoryName: "易车",
        duration: "",
        title: "",
        mp4Link: "",
        imgelink: "",
        pageindex: 1,
        pagesize: 10,
        commentData: [],
        hotcommentData: [],
        isshowcomment: !1,
        isshowhotcomment: !1,
        isloading: !0,
        winHeight: 0
    },
    onLoad: function(o) {
        var t = this;
        console.log(o), t.setData({
            videoid: o.id,
            author: decodeURIComponent(o.Author),
            publishTime: decodeURIComponent(o.PublishTime),
            totalVisit: decodeURIComponent(o.TotalVisit),
            categoryName: decodeURIComponent(o.CategoryName),
            duration: decodeURIComponent(o.Duration),
            title: decodeURIComponent(o.Title),
            mp4Link: decodeURIComponent(o.Mp4Link),
            imgelink: decodeURIComponent(o.imgelink)
        }), console.log(t.data), this.getVideocomments(), this.getVideohotcomments(), wx.getSystemInfo({
            success: function(o) {
                t.setData({
                    winHeight: o.windowHeight
                });
            }
        });
    },
    getVideocomments: function() {
        var e = this;
        e.data.videoid ? o.getVideocomment(e.data.videoid, 0, e.data.pageindex, e.data.pagesize, function(o) {
            console.log(o);
            var n = o.Data.CommentData, i = o.Data.CommentCount;
            if (n && n.length > 0) for (var a = 0; a < n.length; a++) n[a].createtime = t.formatTimeToString(n[a].createtime);
            e.data.pageindex > 1 ? (console.log(e.data.commentData.concat(n)), n ? e.setData({
                commentData: e.data.commentData.concat(n),
                isloading: !1,
                commentcount: i
            }) : e.setData({
                isloading: !1,
                commentcount: i
            })) : e.setData({
                commentData: n,
                isshowcomment: !!(n && n.length > 0),
                isloading: !1,
                commentcount: i
            });
        }, function(o) {}, function(o) {}) : console.log("videoid is not exist");
    },
    getVideohotcomments: function() {
        var e = this;
        e.data.videoid ? o.getVideocomment(e.data.videoid, 1, 1, 3, function(o) {
            var n = o.Data.CommentData;
            if (console.log(n), n && n.length > 0) for (var i = 0; i < n.length; i++) n[i].createtime = t.formatTimeToString(n[i].createtime);
            e.setData({
                hotcommentData: n,
                isshowhotcomment: !!(n && n.length > 0)
            });
        }, function(o) {
            console.log(o);
        }, function(o) {
            console.log("getVideohotcomments complete");
        }) : console.log("videoid is not exist");
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    scrolltolower: function(o) {
        var t = this;
        t.data.isloading ? console.log("scrolltolower is loading,wait...") : (console.log("scrolltolower=" + t.data.isloading), 
        t.data.isloading = !0, t.data.pageindex = t.data.pageindex + 1, t.getVideocomments(), 
        t.setData({
            isloading: !0
        }));
    },
    onReachBottom: function() {
        console.log("onReachBottom");
        var o = this;
        o.data.isloading = !0, o.data.pageindex = o.data.pageindex + 1, o.getVideocomments(), 
        o.setData({
            isloading: !0
        });
    },
    onShareAppMessage: function() {
        return {
            title: "专业的汽车资讯"
        };
    }
});